﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Environment;

namespace Pixysoft.Weblications.Sango.Protocol
{
    class UsrTacticalFacade
    {
        internal static player_tactical ToTactical(Entities.Usr_Strategy strategy,
            Entities.Usr_Tactical ormtactical, List<Entities.Usr_Tacticalpos> list)
        {
            Entities.Sys_Tactical sys = SysTacticalHelper.search(ormtactical.Tacticaltypecode);

            player_tactical body = ReflectionManager.CreatePojo<player_tactical>();

            body.tacticaltypecode = ormtactical.Tacticaltypecode;
            body.level = strategy.Strategylevel;
            body.name = sys.Tacticalname;
            body.isdefault = SettingHelper.BooleanValue(ormtactical.Isdefault);

            body.value = strategy.Strategyvalue;
            body.description = strategy.Description;

            body.positions = ToTacticalPositions(list);

            return body;
        }

        private static List<player_tacticalpos> ToTacticalPositions(List<Entities.Usr_Tacticalpos> orms)
        {
            List<player_tacticalpos> list = new List<player_tacticalpos>();

            foreach (Entities.Usr_Tacticalpos orm in orms)
            {
                player_tacticalpos body = ReflectionManager.CreatePojo<player_tacticalpos>();
                list.Add(body);

                body.isopen = SettingHelper.BooleanValue(orm.Isopen);
                body.positionindex = orm.Positionindex;
                body.officerprimarycode = orm.Officerprimarycode;
            }

            return list;
        }
    }
}
